/**
 * @name plugin dialog unit
 * @copyright	tcsos	inc
 * @author	周琪
 * @version	v1.0
 */
(function(undefined){
	var dialog = {};
			
	//配置信息
	dialog.config = {
		//样式皮肤
		skin : config.path.plugin + 'dialog/dialog.css?v=' + config.version,				
		//是否能改变大小
		is_resize : true,		
		//顶部按钮
		top: {			
			is_show: true,		//是否显示顶部
			is_move: true,		//是否允许移动
			btn_max: true,		//最大化按钮
			btn_min: true,		//最小化按钮
			btn_close: true,	//关闭按钮
			height:33			//顶部高度
		},
		//是否显示滚动条
		is_scroll:true,		
		//按钮模式		0不用按钮模式，1：确定，2确定/取消		
		btn_mode:0,
		//确定按钮方法
		fix_fun:'',
		//确定按钮传参
		fix_param:{},													
		//是否居中
		is_center:false,				
		//启用锁定背屏
		is_lock_back : false,				
		//图标
		icon: '',
		//窗体名称
		name:'',
		//继承框
		own:'',				
		//标题
		title : 'alert_title',
		//提示框内容
		content : 'alert',
		//内容类型
		content_type : 'http',			
		//最小宽
		min_width : 0,
		//最小高
		min_height : 0,
		//间隙
		space : 38,
		//层级
		zindex: '',	
		//显示器对象		
		screen : {
			h:0,
			w:0
		},
        //样式
        style: {}
	};	
	
	//保存的窗体对象
	dialog.obj = {};
	
	//层次	
	dialog.zindex = 10;		
		
	//弹出iframe窗体	
	dialog.iframe = function(param) {
		//更新层次
		dialog.zindex += 2;		
		param.zindex = dialog.zindex; 
		
		//载入配置信息
		var _config = dialog.init_config(param);                
		
		//如果窗体存在，显示窗体
		if(dialog.obj[_config.name] != undefined) {
			dialog.obj[_config.name].show();
			return;
		}									
        
        _config.style = {
            main_inner:{'border':'2px solid #1aa418', 'box-shadow':'2px 2px 0 #E3E3E3'}    
        }
		
		//生成dialog对象
		dialog.obj[_config.name] = new dialog_obj();		
		dialog.obj[_config.name].init(_config);			
	}
	
	//关闭iframe窗体
	dialog.close_iframe = function(e) {		
		name = $(e.frameElement).attr('dialog_win');
		dialog.obj[name].close();		
		return false;					
	}
		
	//弹出alert窗体	 
	dialog.alert = function(param) {
		
		//配置信息
		param.is_resize = false;
		param.top = {is_show: true, is_move: false, btn_max: false, btn_min: false, btn_close: true, height:33};
		param.is_center = true;
		param.is_lock_back = true;
		param.content_type = 'text';
		param.min_width = 300;
		param.min_height = 120;  								
		
		//更新层次
		dialog.zindex += 2;		
		param.zindex = dialog.zindex; 				
		
		//载入配置信息
		var _config = dialog.init_config(param);
        _config.style = {
            main_inner:{'border':'1px solid #333333', 'box-shadow':'0 1px 10px rgba(0, 0, 0, 0.6)'}    
        }
		
		dialog.obj['alert'] = new dialog_obj();
		dialog.obj['alert'].init(_config);
	}
    
    //结束信息框
    dialog.finish = function(val) {
        var param = {};
        
        if(val.timeout == undefined) {
            val.timeout = 2000;
        }
        
        //成功与否
        val.success = val.success == true ? 'op_success' : 'op_defeated'        
        content = '<div class="' + val.success + '"><div class="op_txt">' + val.content + '</div><span></span></div>';
        
        //配置信息
        param.is_resize = false;
        param.top = {is_show: false, is_move: false, btn_max: false, btn_min: false, btn_close: true, height:33};
        param.is_center = true;
        param.is_lock_back = true;
        param.content_type = 'text';
        param.min_width = 250;
        param.min_height = 133;                                  
        param.content = content;        
        param.style = {
            content:{'background-color':'transparent', 'border':'none'},
            main_lock:{'opacity':'0.2', 'background-color':'#000000'}            
        }
        
        //更新层次
        dialog.zindex += 2;        
        param.zindex = dialog.zindex;                 
        
        //载入配置信息
        var _config = dialog.init_config(param);        
        
        dialog.obj['finish'] = new dialog_obj();                
        dialog.obj['finish'].init(_config);                
        
        //执行close方法
        setTimeout('dialog.close("finish")', val.timeout);
        
        //关闭后执行方法
        if(val.callback) {
            setTimeout(val.callback, val.timeout + 1);
        }                
    }
	
	//关闭alert窗体
	dialog.close = function(name) {                
        name = name == undefined ? 'alert' : name;                
        
        if(dialog.obj[name] == undefined) {
            return;
        }
        
        dialog.obj[name].close();
	}
		
	//载入配置信息
	dialog.init_config = function(param){
		var config = common_fun_obj.clone(dialog.config);				
		for (var key in param) {
			if (config[key] == undefined) {
				continue;
			}
			config[key] = param[key];			
		}
        
        /*if(config.min_width == '' || config.min_width < 1) {
            config.min_width = 800;
        }
        
        if(config.min_height == '' || config.min_height < 1) {
            config.min_height = 500;
        } else {
            config.min_height = parseInt(config.min_height) + config.top.height;
        }*/
        
		return config; 		
	}
		
	//载入皮肤样式	 
	dialog.init_style = function() {		
        
        //IE预先加载背景图片
        if(config.browse.ie) {            
            var _img = new Image();
            _img.src = '/plugin/cooperation_unit/dialog/iedialog.png';
        }                
        
        common_fun_obj.append_style(config.domain.local + dialog.config['skin']);        
	}        
		
	if(window.dialog == undefined) {
		window.dialog = dialog;                    
		dialog.init_style();                
	}
})();



/**
 * dialog对象
 */
function dialog_obj(){
	var dialog_obj = {};		
	
	//dialog配置信息
	dialog_obj._config = {};							
	
	//BOX配置
	dialog_obj.box_obj = {
		main_frame:{
			main:{cls: 'window', cursor: '', event: ''},					//主框
			main_inner: {cls: 'window_inner', cursor: '', event: ''},		//主框，插入内容框
			main_lock:{cls:'back_mask', cursor:'', event:''},				//锁屏
			center:{cls: 'window_content', cursor: '', event: ''},			//中间框
			content:{cls: 'content_main', cursor: '', event: ''},			//内容框
			content_mask: {cls: 'iframeDrag', cursor:'', event:'mask'},		//内容遮罩框
			icon: {cls:'', cursor:'pointer', event:'box_show', label:'<li></li>'},			//ICON图标框
			icon_close: {cls:'', cursor:'pointer', event:'box_close', label:'<a></a>'} //ICON关闭
		},
		out_frame:{
			head_l: {cls: 'window_k_tl',cursor: 'nw-resize', event:'mouse_down'},			//左上
			head_t: {cls: 'window_k_t',cursor: 'n-resize', event:'mouse_down'},				//顶部
			head_r: {cls: 'window_k_tr',cursor: 'ne-resize', event:'mouse_down'},			//右上
			center_l: {cls: 'window_k_l',cursor: 'e-resize', event:'mouse_down'},			//左边
			center_r: {cls: 'window_k_r',cursor: 'e-resize', event:'mouse_down'},			//右边
			foot_l: {cls: 'window_k_dl',cursor: 'sw-resize', event:'mouse_down'},			//左下
			foot_r: {cls: 'window_k_dr',cursor: 'se-resize', event:'mouse_down'},			//右下
			foot_b: {cls: 'window_k_d',cursor: 'n-resize', event:'mouse_down'}				//底部
		},
		top_frame:{
			top:{cls:'window_top', cursor:'', event:'mouse_down'},							//菜单
			ico1:{cls:'ico1', cursor:'', event:'box_min', label:'<a></a>'},					//最小化
			ico2:{cls:'ico2', cursor:'', event:'box_max', label:'<a></a>'},					//最大化
			ico4:{cls:'ico4', cursor:'', event:'box_reset', label:'<a></a>'},				//还原
			ico3:{cls:'ico3', cursor:'', event:'box_close', label:'<a></a>'}				//关闭		
		},
		btn_frame:{
			cancle:{cls:'btn_fix', cursor:'', event:'box_close', label:'<a></a>'}							//取消按钮
		}	
	}
	
	//初始化
	dialog_obj.init = function(config) {				
				
		//克隆配置	
		dialog_obj._config = common_fun_obj.clone(config);		
		
		dialog_obj.box_obj = common_fun_obj.clone(dialog_obj.box_obj); 										
		
		//窗体生成
		dialog_box.build();
		
		//追加进入body
		$(document.body).append(dialog_obj.box_obj.main_frame.main.get_obj());				                              
		
		//选中当前窗口
		dialog_obj.box_obj.main_frame.main.fun().selected();
						
		//锁背屏				
		if(dialog_obj._config.is_lock_back) {
			dialog_obj.box_obj.main_frame.main.fun().lock_back_box();			
		}                
				
		if(dialog_obj._config.is_center) {
			//设为居中
			dialog_obj.box_obj.main_frame.main.fun().box_center();
		} else {
			//随机坐标
			dialog_obj.box_obj.main_frame.main.fun().box_random();
		}
        
        //如果最小宽高为0，默认打开全屏
        if(config.min_width < 1 && config.min_height < 1) {            
            dialog_obj.box_obj.main_frame.main.set_css('width', 800);
            dialog_obj.box_obj.main_frame.main.set_css('height', 500);
            dialog_obj.box_obj.main_frame.main.fun().box_random();
            dialog_obj.box_obj.main_frame.main.event().box_max();
        }
		
		//显示主框
		dialog_obj.box_obj.main_frame.main.set_css('display', '');                        
	}										
			 
	//窗体生成
	dialog_box.build = function() {
		//配置信息
		var _config = dialog_obj._config;		 				
									
		//创建所有窗体，并初始化
		var key = ['main_frame', 'top_frame'];
		
		if(_config.is_resize) {
			key.push('out_frame');
		}
		
		if(_config.btn_mode > 0) {
			key.push('btn_frame');
		}
		
		for (var i in key) {
			//BOX数据
			var box_data = dialog_obj.box_obj[key[i]];									                       
			for(var n in box_data) {				
				if(n == 'toString' || n == 'valueOf') {
					continue;
				}														
				var datarow = box_data[n];
				var box_obj = new dialog_box();						
								
				//初始化BOX
				box_obj.init({
					name: n,				//名称 
					datarow: datarow,		//标签数据 					
					list_box: dialog_obj.box_obj,		//所有窗体对象 
					conf: dialog_obj._config 			//配置信息
				});
                
                if(_config.style[n]) {
                    for(var s in _config.style[n]) {
                        box_obj.set_css(s, _config.style[n][s]);
                    }                    
                }
				
				dialog_obj.box_obj[key[i]][n] = box_obj;
			}					
		}		
		
		//设置主框
		var main_box = dialog_obj.box_obj.main_frame.main;
		main_box.set_css('width', _config.min_width + 'px');
		main_box.set_css('height', _config.min_height + 'px');
		main_box.set_css('z-index', _config.zindex);
		
		//将主框隐藏掉
		main_box.set_css('display', 'none');									
		
		//主插入框
		var main_inner = dialog_obj.box_obj.main_frame.main_inner;
		main_box.append_box(main_inner);  
		
		//设置中间
		var center_box = dialog_obj.box_obj.main_frame.center; 
		main_inner.append_box(center_box);		
		
		//允许改变窗体
		if(_config.is_resize) {
			for(var i in dialog_obj.box_obj.out_frame) {                                
				if(i == 'toString' || i == 'valueOf') {
					continue;
				}                                
                                
				main_inner.append_box(dialog_obj.box_obj.out_frame[i]);
			}
		}											
		
		//允许显示顶部
		if(_config.top.is_show) {
			var top_box = dialog_obj.box_obj.top_frame.top; 
			top_box.get_obj().html('<div class="bj" style="-moz-user-select:none;" onselectstart="return false;" onselect="document.selection.empty();"><span></span>&nbsp;&nbsp;' + _config.title + '</div>');			
			
			//将ico对象追加进入
			var span_obj = top_box.get_obj().find('span');			
			for(var i in dialog_obj.box_obj.top_frame) {
				if(i == 'toString' || i == 'valueOf' || i == 'top') {
					continue;
				}				
				
				if(!_config.top.btn_max && (i == 'ico2' || i == 'ico4')) {					
					continue;
				}
				
				if(!_config.top.btn_min && i == 'ico1') {
					continue;
				}
												
				span_obj.append(dialog_obj.box_obj.top_frame[i].get_obj());
			}									
			
			//将还原隐藏
			dialog_obj.box_obj.top_frame['ico4'].set_css('display', 'none');
							
			//追加进入中间
			center_box.append_box(top_box);
		}
		
		//设置内容框
		var content_box = dialog_obj.box_obj.main_frame.content;
		content_box.set_css('height', (_config.min_height - _config.top.height - 3) + 'px');
		content_box.set_css('width', (_config.min_width - 3) + 'px');
		center_box.append_box(content_box);
		
		//设置内容遮罩
		var mask_box = dialog_obj.box_obj.main_frame.content_mask;
		mask_box.get_obj().hide();
		content_box.append_box(mask_box);
		
		//创建内容
		var content_obj = '';
		if(_config.content_type == 'http') {			
			var load_obj = $('<div><span>正在努力为您加载...</span></div>');						
			load_obj.attr('class', 'load_back');			                                    
			var content_obj = $('<iframe></iframe>');                        
            
			content_obj.attr({                                
				'width':'100%',
				'height':'100%',
				'frameborder':'0',				
				'dialog_win':_config.name,
				'display': 'block'
			});
			//是否显示滚动			
			if(!_config.is_scroll) {				
				content_obj.attr('scrolling', 'no');	
			}											
            
            if(config.browse.ie && config.browse.version == '6.0') {
                //处理iframe空白,针对IE6写,加载                                                
                
                setTimeout(function(){                    
                    content_obj.attr('src', _config.content);
                    
                    content_obj.load(function(){
                        load_obj.remove();                            
                    });                                        
                }, 0);
            } else {
                content_obj.attr('src', _config.content);
                content_obj.load(function(){
                    load_obj.remove();                            
                });
            }                        
            
			content_box.get_obj().append(load_obj);			 								                        
		} else {			
			content_obj = $('<div></div>');
			content_obj.attr('class', 'text_content');
			content_obj.html(_config.content);
		}
				
		content_box.get_obj().append(content_obj);                        
		
		//设置ICON图标
		if (_config.icon) {
			var icon_box = dialog_obj.box_obj.main_frame.icon;
            icon_box.get_obj().attr('title', _config.title);
            $('#' + _config.own).append(icon_box.get_obj());                        						            
            
			//ICON关闭
			icon_box.append_box(dialog_obj.box_obj.main_frame.icon_close);
            icon_box.get_obj().append('<img src="' + _config.icon + '" width="19px" height="19px" /><p>' + _config.title.substring(0, 4) + '</p>');
		}				
		
		//启用按钮
		if(_config.btn_mode > 0) {
			var cancle_btn = dialog_obj.box_obj.btn_frame.cancle;
			var bottom_btn_div = $('<div></div>');
			bottom_btn_div.attr('class', 'bottom_btn_div');
			
			//确定按钮绑定事件
			if(_config.btn_mode > 1) {								
				var fix_btn = $('<a></a>');
				fix_btn.attr('class', 'btn_fix');
				fix_btn.html('确&nbsp;定');				
				fix_btn.bind({
					click:function(){
						fix_btn.html('操作中...');
						fix_btn.attr('class', 'btn_fix_disable');
						cancle_btn.get_obj().attr('class', 'btn_fix_disable');
						fix_btn.unbind('click');
						cancle_btn.get_obj().unbind('mousedown');
						dialog_obj.box_obj.top_frame.ico3.get_obj().unbind('mousedown');										
					}
				});
				fix_btn.bind('click', _config.fix_param, _config.fix_fun);				
				bottom_btn_div.append(fix_btn);				
			}
						
			var str = _config.btn_mode == 1 ? '确&nbsp;定' : '取&nbsp;消';			
			cancle_btn.get_obj().html(str);
			bottom_btn_div.append(cancle_btn.get_obj());						
			content_box.get_obj().append(bottom_btn_div);				
		}					
	} 
	
	/*+------------------------------------------外部调用方法----------------------------------------------+*/
	return {
		//初始化
		init:function(config) {			
			dialog_obj.init(config);
		},
		//获取ICON对象
		get_icon:function() {
			return dialog_obj.box_obj.main_frame.icon; 
		},
		//获取head对象
		get_head:function() {
			return dialog_obj.box_obj.top_frame.top;
		},								
		//获取遮罩对象
		get_mask:function() {
			return dialog_obj.box_obj.main_frame.content_mask;
		},
		//显示窗体
		show:function() {
			dialog_obj.box_obj.main_frame.main.fun().show_main(true);
			dialog_obj.box_obj.main_frame.main.fun().change_zindex();
			dialog_obj.box_obj.main_frame.main.fun().selected();						
		},
        //设置背景色
        set_backcolor:function(color) {
            dialog_obj.box_obj.main_frame.content.set_css('background-color', color);
        },
        //设置边框
        set_border:function(border) {
            dialog_obj.box_obj.main_frame.content.set_css('border', border);
        },
		//关闭窗口
		close:function() {
			dialog_obj.box_obj.main_frame.main.fun().close_main();
		}
	}		
};



/**
 * BOX对象
 */
function dialog_box() {
	
	//初始化对象
	var dialog_box = {
		//事件对象
		event:{},
		//方法对象
		fun:{},
		//定位
		position:{}		
	};		
	
	//配置信息
	var conf = {};		
	
	//DIV对象
	var box_obj = {
		name:'',					//名称		
		datarow:{},					//数据
		is_click:false,				//是否被点击
		mouse_position:{x:0, y:0},	//鼠标所在坐标
		label:$('<div></div>')		//标签
	}	
	
	//主框对象
	main_box = {		
		mouse_position: {x:0, y:0},		//鼠标所在坐标
		size:{w:0, h:0},				//宽高
		offset:{left:0, top:0},			//XY
		datarow:{}						//数据
	};
	
	//所有的窗体对象
	var list_box = {};
		
	//BOX方法
	dialog_box.fun.unit = {		
		//锁背屏
		lock_back_box:function() {
			var h = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);					           
			list_box.main_frame.main_lock.set_css('z-index', (list_box.main_frame.main.get_css('z-index') - 1));                        
            list_box.main_frame.main_lock.set_css('height', h + 'px');
			list_box.main_frame.main.get_obj().before(list_box.main_frame.main_lock.get_obj());			            
		},
		//BOX居中
		box_center:function() {
			var width, height;
			var main_box = list_box.main_frame.main;
			
			width = main_box.get_css('width').replace('px', '') / 2;						
			height = main_box.get_css('height').replace('px', '') / 2;
			
			//屏幕高度，一半						        
            screen_height = Math.max(document.documentElement.scrollTop, document.body.scrollTop) + (document.documentElement.clientHeight / 2);            
						
			main_box.set_css('left', (conf.screen.w / 2) - width);								
			main_box.set_css('top', screen_height - height);						
		},
		//随机位置
		box_random:function() {
			var main_box = list_box.main_frame.main;
			
			width = main_box.get_css('width').replace('px', '');
			height = main_box.get_css('height').replace('px', '');                        
			
			_left =  Math.random() * (conf.screen.w - width);
			_top = Math.random() * (conf.screen.h - height);                        
            
            _top = _top < 33 ? 33 : _top;            
            _left = _left < 0 ? 0 : _left;
            
			main_box.set_css('left', _left);
			main_box.set_css('top', _top);			
		},		
		//显示所有的拖动BOX
		show_all_drag:function(flag) {			
			for(var i in list_box.out_frame) {
				if(i == 'toString' || i == 'valueOf') {
					continue;
				}
				list_box.out_frame[i].set_show(flag);
			}
		},
		//显示主窗体
		show_main:function(flag) {
			flag = flag ? 'visible' : 'hidden';
			list_box.main_frame.main.set_css('visibility', flag);
		},
		//关闭窗体
		close_main:function() {                                                                                            
            
            //隐藏主框
            dialog_box.fun.unit.show_main(false);
            
            //延迟动作删除，为的是清空SRC
            setTimeout(function(){
                //如果是http模式，因先清除iframe的src
                if(conf.content_type == 'http') {
                    list_box.main_frame.main.get_obj().find('iframe').attr('src', '');
                }            
                
                //删除主窗体和ICON窗体
                list_box.main_frame.main.get_obj().remove();
                list_box.main_frame.icon.get_obj().remove();
            
                //删除背屏
                list_box.main_frame.main_lock.get_obj().remove();                        
            
                //清除JSON对象
                delete dialog.obj[conf.name];
            }, 200);            			
		},
		//改变层级
		change_zindex:function() {
			//改变层级
			dialog.zindex += 2;
			if(dialog.zindex > 9999) {
				dialog.zindex = 9999;
			}												
			list_box.main_frame.main.set_css('z-index', dialog.zindex);								
		},
		//显示遮罩
		show_mask:function(flag) {						            
			list_box.main_frame.content_mask.set_show(flag);					
		},
		//显示所有遮罩
		show_all_mask:function(flag) {									
			//循环显示遮罩			
			for(var i in dialog.obj) {
				if(i == 'toString' || i == 'valueOf') {
					continue;
				}
                                
				dialog.obj[i].get_mask().set_show(flag);										
			}			
		},
		//重新获取屏幕尺寸
		reset_screen:function() {
			conf.screen = common_fun_obj.screen();
		},
		//选中当前窗口
		selected:function() {						
			//改变所有head			
			for(var i in dialog.obj) {
				if(i == 'toString' || i == 'valueOf') {
					continue;
				}
                                
				dialog.obj[i].get_head().add_class('hover');                     
                
                if(conf.own) {
				    dialog.obj[i].get_icon().remove_class('hover');										
                }
			}
			
			list_box.top_frame.top.remove_class('hover');
            if(conf.own) {
			    list_box.main_frame.icon.add_class('hover');
            }
		}		
	}
	
	
	//BOX事件
	dialog_box.event.unit = {
		//是否右键点击
		is_right:function(e) {					
			//不允许右键点击
			if(e.which == 3) {				
				return true;
			}
			
			return false;
		},		
		//显示窗体
		box_show:function(e) {
			//更改层级
			dialog_box.fun.unit.change_zindex();
			
			//显示主框体						
			dialog_box.fun.unit.show_main(true);

			//主框体被选中			
			dialog_box.fun.unit.selected();
			
			//终止后面的事件
			common_fun_obj.done(e);
		},		
		//窗体最小化
		box_min:function(e) {
			//禁止右键
			if(dialog_box.event.unit.is_right(e)) {
				return;
			}
			
			dialog_box.fun.unit.show_main(false);			
			
			//终止后面的事件
			common_fun_obj.done(e);
		},
		//关闭窗体
		box_close:function(e) {
			//禁止右键
			if(dialog_box.event.unit.is_right(e)) {
				return;
			}
			
			dialog_box.fun.unit.close_main();			
			
			//终止后面的事件
			common_fun_obj.done(e);						
		},				
		//窗体最大化
		box_max:function(e) {	
		
			//禁止右键            
			if(e != undefined && dialog_box.event.unit.is_right(e)) {
				return;
			}										
			
			//重新获取屏幕尺寸
			dialog_box.fun.unit.reset_screen();			
															
			//数据保存
			list_box.main_frame.main.get_obj().data('main_room', {
				left: list_box.main_frame.main.get_css('left').replace('px', ''),
				top: list_box.main_frame.main.get_css('top').replace('px', ''),
				width: list_box.main_frame.main.get_css('width').replace('px', ''),
				height: list_box.main_frame.main.get_css('height').replace('px', '')
			});						 		                        
			
			//计算max_width/max_height
			//max_width = conf.screen.w - (conf.space * 2);
			//max_height = conf.screen.h - (conf.space * 2) - 20;
            max_width = conf.screen.w;
            max_height = conf.screen.h;
						
			//设置LEFT/TOP空隙
			//list_box.main_frame.main.set_css('left', conf.space);
			//list_box.main_frame.main.set_css('top', conf.space);
            list_box.main_frame.main.set_css('left', 0);
            list_box.main_frame.main.set_css('top', 0);
            
            //全屏将padding设置为0
            list_box.main_frame.main.set_css('padding', 0);            
			
			//设置主窗体width/height
			list_box.main_frame.main.set_css('width', max_width);
			list_box.main_frame.main.set_css('height', max_height);					 															
			
			//设置内容宽高
			//list_box.main_frame.content.set_css('height', max_height - conf.top.height);
			//list_box.main_frame.content.set_css('width', max_width - 2);			
            list_box.main_frame.content.set_css('width', max_width);            
            list_box.main_frame.content.set_css('height', max_height);            
			
			//不能移动
			conf.top.is_move = false;
			
			//设置最大化隐藏，最小化显示
			list_box.top_frame.ico2.set_show(false);
			list_box.top_frame.ico4.set_show(true);
			
			//将所有拖动隐藏
			dialog_box.fun.unit.show_all_drag(false);																			
			
			//终止后面的事件
			common_fun_obj.done(e);			
		},		
		//窗体还原
		box_reset:function(e) {
			//禁止右键
			if(dialog_box.event.unit.is_right(e)) {
				return;
			}
			
			var main_room = list_box.main_frame.main.get_obj().data('main_room');						
														
			//还原外框
			list_box.main_frame.main.set_css('left', main_room.left + 'px');
			list_box.main_frame.main.set_css('top', main_room.top + 'px');
			list_box.main_frame.main.set_css('width', main_room.width + 'px');
			list_box.main_frame.main.set_css('height', main_room.height + 'px');
            
            //根据全屏padding设为0了，那么还原就要设置回来
            list_box.main_frame.main.set_css('padding', 8);			        
			
			//还原内容框	
			list_box.main_frame.content.set_css('width', (main_room.width - 2) + 'px');
			list_box.main_frame.content.set_css('height', (main_room.height - conf.top.height) + 'px');
			
			//允许移动
			conf.top.is_move = true;
			
			//xian最大化显示，最小化隐藏
			list_box.top_frame.ico2.set_show(true);
			list_box.top_frame.ico4.set_show(false);
			
			//将所有拖动大小显示
			dialog_box.fun.unit.show_all_drag(true);
			
			//终止后面的事件
			common_fun_obj.done(e);
		},		
		//遮罩事件
		mask:function() {
			//改变层级
			dialog_box.fun.unit.change_zindex();
			
			//显示所有遮罩
			dialog_box.fun.unit.show_all_mask(true);			
			
			//隐藏当前遮罩			
			list_box.main_frame.content_mask.set_show(false);
			
			//选中当前窗口
			dialog_box.fun.unit.selected();																							
		},				
		//改变窗体大小事件
		mouse_down:function(e) {
			if(box_obj.is_click) {
				return;
			}												                        
			
			//禁止右键
			if(dialog_box.event.unit.is_right(e)) {
				return;
			}									  							
			
			//不允许选择文本
			common_fun_obj.select_text(false);												 																								
			
			//重新获取屏幕尺寸
			dialog_box.fun.unit.reset_screen();
			
			//执行遮罩
			dialog_box.event.unit.mask();
			
			//显示当前遮罩			
			list_box.main_frame.content_mask.set_show(true);																																													
			
			//改变鼠标样式
			box_obj.label.css('cursor', 'default');						

			//设置为已被点击																	
			box_obj.is_click = true;											
			
			//光标点击后的X/Y
			box_obj.mouse_position = common_fun_obj.get_mouse_pos(e);
			
			//主框宽度
			main_box.size = {
				w: list_box.main_frame.main.get_obj().width(),
				h: list_box.main_frame.main.get_obj().height()
			}																	
			
			//主框left，top
			main_box.offset = list_box.main_frame.main.get_obj().offset();
			
			if (config.browse.ie) {
				this.setCapture();							
			} else {
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);  				
			}
			
			$(document).bind('mousemove', dialog_box.event.unit.mouse_move);
			$(document).bind('mouseup', dialog_box.event.unit.mouse_up);														                                    					 			 											
		},
		//鼠标放开事件
		mouse_up:function() {						
			if (config.browse.ie) {
				this.releaseCapture();
			} else {
				window.releaseEvents(dialog_box.event.unit.mouse_move);
			}
		
			box_obj.is_click = false;
			
			//允许选择文本
			common_fun_obj.select_text(true);						
			
			//改变鼠标样式
			box_obj.label.css('cursor', box_obj.datarow.cursor);			
			
			//隐藏遮罩
			list_box.main_frame.content_mask.set_show(false);			
			
			//清除绑定事件									
			$(document).unbind('mousemove', dialog_box.event.unit.mouse_move);
			$(document).unbind('mouseup', dialog_box.event.unit.mouse_up);			
		},
		//鼠标移动
		mouse_move:function(e) {						
			var offset = common_fun_obj.get_mouse_pos(e);
			
			switch(box_obj.name) {
				//拖动
				case 'top':					
					if(!conf.top.is_move) {
						break;
					}										
					dialog_box.position.move(offset);
					break;
				//上拖动
				case 'head_t':                
					dialog_box.position.up(offset);
					break;
				//下拖动
				case 'foot_b':
					dialog_box.position.next(offset);
					break;
				//左拖动
				case 'center_l':
					dialog_box.position.left(offset);
					break;
				//右拖动
				case 'center_r':
					dialog_box.position.right(offset);
					break;
				//左上拖动
				case 'head_l':
					dialog_box.position.left(offset);
					dialog_box.position.up(offset);
					break;
				//右上拖动
				case 'head_r':
					dialog_box.position.up(offset);
					dialog_box.position.right(offset);
					break;
				//左下拖动
				case 'foot_l':
					dialog_box.position.left(offset);
					dialog_box.position.next(offset);
					break;
				//右下拖动
				case 'foot_r':
					dialog_box.position.right(offset);
					dialog_box.position.next(offset);
					break;				
			}			
		}
	}
	
	//移动位置
	dialog_box.position = {
		//移动主框位置
		move:function(offset) {						
			x = offset.x - (box_obj.mouse_position.x - main_box.offset.left);
			y = offset.y - (box_obj.mouse_position.y - main_box.offset.top);                        

            //不能向上和向左拖完
			y = y <= 33 ? 33 : y;						
			x = x <= 0 ? 0 : x;						                        
            
            //向下拖            
            y = y >= (conf.screen.h - conf.top.height - 33) ? conf.screen.h - conf.top.height - 33 : y;
            			
			list_box.main_frame.main.set_css('left', x);
			list_box.main_frame.main.set_css('top', y);																														 					                      
		},
		//左拖动
		left:function(offset) {
			w = box_obj.mouse_position.x - offset.x;								
			if((main_box.size.w + w) < conf.min_width || offset.x < conf.space) {
				return;
			}
			list_box.main_frame.content.set_css('width', (main_box.size.w + w - 2) + 'px');
			list_box.main_frame.main.set_css('width', (main_box.size.w + w) + 'px');
			list_box.main_frame.main.set_css('left', (main_box.offset.left - w) + 'px');						
		},
		//右拖动
		right:function(offset) {
			w = offset.x - box_obj.mouse_position.x + main_box.size.w;
			if(w < conf.min_width || offset.x > (conf.screen.w - (conf.space * 2))) {
				return;
			}
			list_box.main_frame.content.set_css('width', (w - 2) + 'px');
			list_box.main_frame.main.set_css('width', w + 'px');																																																										
		},
		//上拖动
		up:function(offset) {            
			h = box_obj.mouse_position.y - offset.y;								                                    
			if((main_box.size.h + h) < conf.min_height || offset.y < conf.space) {				
				return;
			}
			list_box.main_frame.content.set_css('height', (main_box.size.h + h - conf.top.height) + 'px');						
			list_box.main_frame.main.set_css('height', (main_box.size.h + h) + 'px');
			list_box.main_frame.main.set_css('top', (main_box.offset.top - h) + 'px');									
		},
		//下拖动
		next:function(offset) {
			h = offset.y - box_obj.mouse_position.y + main_box.size.h;
			if(h < conf.min_height || offset.y > (conf.screen.h - conf.space)) {
				return;
			}
			list_box.main_frame.content.set_css('height', (h - conf.top.height) + 'px');
			list_box.main_frame.main.set_css('height', h + 'px');						
		}
	}
	
	/*+------------------------------------------外部调用方法----------------------------------------------+*/
	return {		
        //获取事件
        event:function() {
            return dialog_box.event.unit;
        },
		//获取方法
		fun:function() {
			return dialog_box.fun.unit;
		},
		//设置对象
		set_obj:function(obj) {
			box_obj.label = obj;
		},			
		//获取对象
		get_obj:function() {
			return box_obj.label;								
		},
		//设置显示对象		
		set_show:function(show_flag) {
			if(show_flag) {
				box_obj.label.show();
				return;
			}
			box_obj.label.hide();
		},
		//添加CLASS
		add_class:function(name) {
			box_obj.label.addClass(name);			
		},
		//删除CLASS
		remove_class:function(name) {
			box_obj.label.removeClass(name);
		},
		//设置CSS		
		set_css:function(k, v) {
			box_obj.label.css(k, v);
		},
		//获取CSS
		get_css:function(k) {
			return box_obj.label.css(k); 
		},
		//追加BOX
		append_box:function(client) {
			box_obj.label.append(client.get_obj());
		},
		/**
		 * 初始化box对象
		 * @param {Object} param {
		 * name:名称 
		 * datarow:标签数据 					
		 * list_box:所有窗体对象
		 * conf:配置信息
		 * }
		 */
		init:function(param) {																	
			//配置													
			conf = param.conf;						
			
			//所有窗体对象
			list_box = param.list_box;		
			
			//子框			
			box_obj.datarow = param.datarow;
			box_obj.name = param.name;
			
			//更改标签
			if(box_obj.datarow.label) {
				box_obj.label = $(box_obj.datarow.label);	
			}
			
			//设置CLASS
			if (box_obj.datarow.cls) {
				box_obj.label.attr('class', box_obj.datarow.cls);
			}															
			
			//设置光标样式
			if (box_obj.datarow.cursor) {
				box_obj.label.css('cursor', box_obj.datarow.cursor);
			}
			
			//如果屏幕尺寸不存在，就初始化
			if (conf.screen.w < 1) {
				dialog_box.fun.unit.reset_screen();
			}
			
			//绑定事件
			if(box_obj.datarow.event) {
				box_obj.label.bind('mousedown', dialog_box.event.unit[box_obj.datarow.event]);
			}							
		}
	}	
}
